package com.smec.remes.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;

/**
 * Created by Administrator on 2018/1/8.
 */

public class GetFullUrl {
    /**
     * 返回接口完整路径
     *
     * @param uri
     * @param params
     * @return
     */
    public static String getFullUrl(String uri, Map<String, String> params) {
        String base_url = "http://bpmpublic.smec-cn.com:8011/WmsMobileService/";   //正式环境
        StringBuffer buf = new StringBuffer(base_url + uri);
        if (params != null && !params.isEmpty()) {
            buf.append("?");
        }
        if (params == null) {
            return buf.toString();
        }
        boolean flag = false;
        for (String key : params.keySet()) {
            String value = params.get(key);
            if (value == null || "null".equals(value)) {
                value = "";
            }
            if (flag) {
                buf.append("&");
            }
            flag = true;
            buf.append(key);
            buf.append("=");
            try {
                buf.append(URLEncoder.encode(value, "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        return buf.toString();
    }
}
